package com.huawei.translate.utils;

import org.springframework.stereotype.Component;

import java.util.Base64;

@Component
public class Encryptor {

    private static final String ENCODE = "utf-8";

    public String base64TryEncode(String source) {
        try {
            return Base64.getEncoder().encodeToString(source.getBytes(ENCODE));
        } catch (Exception e) {
            e.printStackTrace();
            return  null;
        }
    }

    public String base64TryDecode(String source) {
        try {
            return new String(Base64.getDecoder().decode(source), ENCODE);
        } catch (Exception e) {
            return null;
        }
    }
}
